/**
 * 
 */
package com.wolfpire.workflow.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wolfpire.system.common.EasyuiPage;
import com.wolfpire.system.common.EasyuiPagination;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.Result;
import com.wolfpire.workflow.om.Forms;
import com.wolfpire.workflow.spring.FormsService;

/**
 * 表单管理
 * @author lihd
 *
 */

@Controller
@RequestMapping("/forms")
public class FormsController {
	
	@Resource private FormsService formsService;
	
	@RequestMapping("/list")
	public ModelAndView list() {
		return new ModelAndView("workflow/forms/forms_list");
	}
	
	@ResponseBody
	@RequestMapping("/queryList")
	public EasyuiPagination<Forms> queryList(EasyuiPage<Forms> page, Forms filterForms) {
		Page<Forms> formses = this.formsService.setPageDataList(page, filterForms);
		return new EasyuiPagination<Forms>(formses);
	}
	
	@RequestMapping(value = "/add")
	public ModelAndView add(HttpSession session) {
		ModelAndView mv = new ModelAndView("workflow/forms/forms_edit");
		mv.getModelMap().put("forms", new Forms());
		return mv;
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(Long formTypeId) {
		ModelAndView mv = new ModelAndView("workflow/forms/forms_edit");
		if (null != formTypeId) {
			Forms forms = this.formsService.get(formTypeId);
			mv.getModelMap().put("forms", forms);
		}
		return mv;
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public Result delete(Long formTypeId) {
		try {
			this.formsService.delete(formTypeId);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
	
	@ResponseBody
	@RequestMapping("/save")
	public Result save(Forms forms) {
		try {
			this.formsService.saveOrUpdate(forms);
			return new Result(true, "保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "保存失败");
		}
	}
	
	@ResponseBody
	@RequestMapping("/forms")
	public List<Forms> forms(Forms forms) {
		return this.formsService.list(forms);
	}
}
